package gui.BeginDialogue;

import gui.Error.ErrorDialogue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JDialog;

public class BeginDialogue extends JDialog implements ActionListener , IBeginDialog{


	private static final long serialVersionUID = -3094778735477074250L;

	private boolean exit=true;
	private PanelNewConcourt pnc;
	private LoadFilePanel lfp;
	
	
	public BeginDialogue(GameInformation g){
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLocation(10,10);
		getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.PAGE_AXIS));
		pnc = new PanelNewConcourt(this,g);
		add(pnc);
		lfp=new LoadFilePanel(this,this,g);
		add(lfp);
		add(new ThrowConcourt(this));
		pack();
		setMode();
		setVisible(true);
	}


	public void actionPerformed(ActionEvent arg0) {
		try {
			pnc.newConcourt();
			lfp.loadFile();
			exit=false;
			dispose();
		} catch (Exception e) {
			new ErrorDialogue(this,e.getMessage());
		}
	}
	
	public void dispose(){
		if(exit)
			System.exit(0);
		super.dispose();
	}


	@Override
	public void setMode() {
		lfp.block();
		pnc.block();
	}
	
}
